home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
COMMUNIC
/
TERMINAL
/
1589.ZIP
/
WINSIZE.C
< prev
Wrap
Text File
|
1989-02-28
|
4KB
|
147 lines
#define SHRINKWINDOWS
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <windows.h>
#include "icu_user.h"
/**/
/*doc************************************************************************
*
* NAME
*
* SaveWindowSize() - save size of window in ascii file
*
* FORMAT
*
* SaveWindowSize(name,rect)
* char *name
* LPRECT rect
*
* DESCRIPTION
*
*
* RETURN VALUE
* TRUE - error saving size
* FALSE - ok
*
* REFERENCES
*
*end************************************************************************/
SaveWindowSize( win_size )
struct window_size *win_size;
{
/****************************************
* local variable declarations *
****************************************/
int hdl, size, ret, found;
struct window_size temp;
/****************************************
* start of function code *
****************************************/
size = sizeof( struct window_size );
/****************************************
* open file *
****************************************/
OPEN:
hdl = open(SIZEFILE,O_BINARY|O_RDWR|O_CREAT,0666);
if (hdl < 0)
return(TRUE);
/****************************************
* read each line looking for one that *
* matches the passed 'name' *
****************************************/
found = FALSE;
ret = read( hdl,(char *) &temp, size );
while (ret > 0) {
if (!strcmp( win_size->app_name, temp.app_name )) {
lseek( hdl,-(long)size, SEEK_CUR );
break;
}
ret = read( hdl,(char *) &temp, size );
if ( ret > 0 && ret != size ) { /* File is bad! ; recreate */
close( hdl );
unlink( SIZEFILE );
goto OPEN;
}
}
/****************************************
* write the new coordinates *
****************************************/
ret = write( hdl, (char *) win_size, size );
close(hdl);
if ( ret != size )
return(TRUE);
return(FALSE);
}
/**/
/*doc************************************************************************
*
* NAME
*
* ReadWindowSize() - read size of window from file
*
* FORMAT
*
* ReadWindowSize(name,rect)
* char *name
* LPRECT rect
*
* DESCRIPTION
*
*
* RETURN VALUE
* TRUE - error reading size or size not found
* FALSE - ok
*
* REFERENCES
*
*end************************************************************************/
ReadWindowSize( win_size )
struct window_size *win_size;
{
/****************************************
* local variable declarations *
****************************************/
int hdl, size, ret;
char name[12];
/****************************************
* start of function code *
****************************************/
size = sizeof( struct window_size );
strcpy( name, win_size->app_name );
/****************************************
* open file *
****************************************/
hdl = open(SIZEFILE,O_BINARY|O_RDONLY);
if (hdl < 0) {
return(TRUE);
}
/****************************************
* read each line looking for one that *
* matches the passed 'name' *
****************************************/
ret = read( hdl,(char *) win_size, size );
while (ret == size ) {
if (!strcmp( win_size->app_name, name )) {
close(hdl);
return(FALSE);
}
ret = read( hdl,(char *) win_size, size );
if ( ret > 0 && ret != size ) { /* File is bad! ; recreate */
close( hdl );
unlink( SIZEFILE );
break;
}
}
close(hdl);
memset( (char *) win_size, '\0', size );
return(TRUE);
}